package Boundry;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JPanel;

import Boundry.GenericTools.IPanelOperation;
import Boundry.GenericTools.InputPanel;
import Controllers.GenericToolsForController.BrowseScreen;
import Controllers.GenericToolsForController.PDFfile;

import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JComboBox;
import javax.swing.JTextPane;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.TitledBorder;
import java.awt.SystemColor;

public class SubmitRequestPanel extends InputPanel implements IPanelOperation,ActionListener
{
        private JTextField tfApplicantName;
        private JTextField tfPosition;
        private JTextField tfEmail;
        private JTextField tfPhone;
        private JTextField tfFilePath;
        private JTextArea taCurrentState;
        private JTextArea taChangeDescription;
        private JTextArea taExecuse;
        private JComboBox<String> cbInfoSystem;
        private JTextArea taNote;
        private JButton btnAddFile;
        private BrowseScreen bs;
        private int selectedItem;
        
        public SubmitRequestPanel()
        {
        	mainPanel.setBounds(0, 0, 896, 380);
        	bs = new BrowseScreen();
                
                JPanel panel = new JPanel();
                panel.setBorder(new TitledBorder(null, "Applicant Details :", TitledBorder.LEADING, TitledBorder.TOP, null, null));
                panel.setToolTipText("");
                panel.setBounds(31, 11, 389, 207);
                mainPanel.add(panel);
                panel.setLayout(null);
                
                tfApplicantName = new JTextField();
                tfApplicantName.setBackground(SystemColor.inactiveCaptionText);
                tfApplicantName.setBounds(125, 25, 142, 20);
                panel.add(tfApplicantName);
                tfApplicantName.setColumns(10);
                
           
                
                tfPosition = new JTextField();
                tfPosition.setBackground(SystemColor.inactiveCaptionText);
                tfPosition.setBounds(125, 68, 142, 20);
                panel.add(tfPosition);
                tfPosition.setColumns(10);
                
                tfEmail = new JTextField();
                tfEmail.setBackground(SystemColor.inactiveCaptionText);
                tfEmail.setBounds(125, 110, 142, 20);
                panel.add(tfEmail);
                tfEmail.setColumns(10);
                
                JLabel lblNewLabel_1 = new JLabel("Applicant Name:");
                lblNewLabel_1.setBounds(20, 25, 103, 14);
                panel.add(lblNewLabel_1);
                
                JLabel lblPosition = new JLabel("Position:");
                lblPosition.setBounds(20, 71, 46, 14);
                panel.add(lblPosition);
                
                JLabel lblEmail = new JLabel("e-mail:");
                lblEmail.setBounds(20, 113, 46, 14);
                panel.add(lblEmail);
                
                JLabel lblPhone = new JLabel("Phone:");
                lblPhone.setBounds(20, 155, 46, 14);
                panel.add(lblPhone);
                
                tfPhone = new JTextField();
                tfPhone.setBackground(SystemColor.inactiveCaptionText);
                tfPhone.setBounds(125, 152, 142, 20);
                panel.add(tfPhone);
                tfPhone.setColumns(10);
                
                JPanel panel_1 = new JPanel();
                panel_1.setBorder(new TitledBorder(null, "Request Details :", TitledBorder.LEADING, TitledBorder.TOP, null, null));
                panel_1.setBounds(450, 11, 417, 358);
                mainPanel.add(panel_1);
                panel_1.setLayout(null);
                
                cbInfoSystem = new JComboBox<String>();
                cbInfoSystem.setBounds(249, 19, 127, 20);
                
                panel_1.add(cbInfoSystem);
                selectedItem=-1;
                cbInfoSystem.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent e) {
                        selectedItem = cbInfoSystem.getSelectedIndex();
                    }	
                });
                
                JLabel lblSystem = new JLabel("System:");
                lblSystem.setBounds(157, 22, 82, 14);
                panel_1.add(lblSystem);
                
                JLabel lblNewLabel = new JLabel("Current state description:");
                lblNewLabel.setBounds(10, 67, 133, 14);
                panel_1.add(lblNewLabel);
                
                JLabel lblNewLabel_2 = new JLabel("Change description:");
                lblNewLabel_2.setBounds(10, 142, 137, 14);
                panel_1.add(lblNewLabel_2);
                
                JLabel lblExecuse = new JLabel("Execuse:");
                lblExecuse.setBounds(10, 214, 133, 14);
                panel_1.add(lblExecuse);
                
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                scrollPane.setBounds(167, 50, 242, 57);
                panel_1.add(scrollPane);
                
                taCurrentState = new JTextArea();
                scrollPane.setViewportView(taCurrentState);
                
                JScrollPane scrollPane_1 = new JScrollPane();
                scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                scrollPane_1.setBounds(169, 129, 240, 57);
                panel_1.add(scrollPane_1);
                
                taChangeDescription = new JTextArea();
                scrollPane_1.setViewportView(taChangeDescription);
                
                JScrollPane scrollPane_2 = new JScrollPane();
                scrollPane_2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                scrollPane_2.setBounds(167, 214, 242, 57);
                panel_1.add(scrollPane_2);
                
                taExecuse = new JTextArea();
                scrollPane_2.setViewportView(taExecuse);
                
                JLabel lblNewLabel_3 = new JLabel("");
                lblNewLabel_3.setIcon(new ImageIcon(SubmitRequestPanel.class.getResource("/ICONS/6_social_cc_bcc.png")));
                lblNewLabel_3.setBounds(0, 11, 32, 32);
                mainPanel.add(lblNewLabel_3);
                
                JPanel paOpt = new JPanel();
                paOpt.setBorder(new TitledBorder(null, "Optional Details :", TitledBorder.LEADING, TitledBorder.TOP, null, null));
                paOpt.setBounds(31, 229, 389, 140);
                mainPanel.add(paOpt);
                paOpt.setLayout(null);
        		JScrollPane sbrText = new JScrollPane();
        		sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        		sbrText.setBounds( 55, 24, 311, 57);
        		paOpt.add(sbrText);
        		
        		taNote = new JTextArea();
        		sbrText.setViewportView(taNote);
        		
        		taNote.setLineWrap(true);
                
                JLabel lblNote = new JLabel("Note:");
                lblNote.setBounds(10, 38, 46, 14);
                paOpt.add(lblNote);
                
                JLabel lblFile = new JLabel("File:");
                lblFile.setBounds(10, 103, 46, 14);
                paOpt.add(lblFile);
                
                tfFilePath = new JTextField();
                tfFilePath.setBounds(57, 100, 210, 20);
                paOpt.add(tfFilePath);
                tfFilePath.setColumns(10);
                
                btnAddFile = new JButton(" ");
                btnAddFile.setBounds(295, 90, 71, 41);
                btnAddFile.setIcon(new ImageIcon(TestingPanel.class.getResource("/ICONS/4_collections_collection.png")));
                paOpt.add(btnAddFile);
                
                btnAddFile.addActionListener(this);
                
                JLabel lblop = new JLabel("New label");
                lblop.setBounds(0, 229, 32, 44);
                lblop.setIcon(new ImageIcon(SubmitRequestPanel.class.getResource("/ICONS/5_content_new_attachment.png")));
                mainPanel.add(lblop);
                
                JLabel lblNewLabel_4 = new JLabel("");
                lblNewLabel_4.setBounds(420, 11, 32, 32);
                mainPanel.add(lblNewLabel_4);
                lblNewLabel_4.setIcon(new ImageIcon(SubmitRequestPanel.class.getResource("/ICONS/4_collections_view_as_list.png")));
                
                
        }
        /*
                 
        private JComboBox cbInfoSystem;
       
         */
       
        
    	@Override
    	public void actionPerformed(ActionEvent e)
    	{
    		bs.ChooseFile();
    		setFilePath( bs.getPath());
    	}
        
        public boolean isChosen() 
        {
        	if (selectedItem == -1 ) 
        		return false;
        	return true;
        }
        
        public int getChosen()
        {
        	 return this.selectedItem;
        }

    	
    	public void addElementToComboBox(String elem)
    	{
    		cbInfoSystem.addItem(elem);
    	}
    	
    	
    	public PDFfile getFile()
        {
        	return bs.getFileToSend();
        }
        
        public String getFilePath()
        {
        	return tfFilePath.getText();
        }
        public void setFilePath(String data)
        {
        	tfFilePath.setText(data);
        	
        }
        
        
        public String getPhone()
        {
        	return tfPhone.getText();
        }
        public void setPhone(String data)
        {
        	tfPhone.setText(data);
        	tfPhone.setEnabled(false);
        }
        
        
        public String getPosition()
        {
        	return tfPosition.getText();
        }
        public void setPosition(String data)
        {
        	 tfPosition.setText(data);
        	 tfPosition.setEnabled(false);
        }
        
        public String getApplicantName()
        {
        	return tfApplicantName.getText();
        }
        public void setApplicantName(String data)
        {
        	tfApplicantName.setText(data);
        	tfApplicantName.setEnabled(false);
        }
        
        public String getEmail()
        {
        	return tfEmail.getText();
        }
        public void setEmail(String data)
        {
        	tfEmail.setText(data);
        	tfEmail.setEnabled(false);
        }
        
        
        public String getCurrentState()
        {
        	return taCurrentState.getText();
        }
        public String getChangeDescription()
        {
        	return taChangeDescription.getText();
        }
        public String getExecuse()
        {
        	return taExecuse.getText();
        }
        public String getNote()
        {
        	return taNote.getText();
        }
        
        @Override
        public String apHelpButton() {
                return "Here any user can submit a new change request to the system";
        }


		@Override
		public String setTitle() {
			return "Submit Request";
		}
}